package faction.maopao;

public class Maopao {
    // 倒排 由 大 -> 小
    public int[] exe(int[] nums, boolean reserve) {
        if(reserve) {
            return reserve(nums);
        } else {
            return unreserve(nums);
        }       
    }

    private int[] reserve(int[] nums) {
        for(int x = 0; x < nums.length; x++) {
            for(int y = nums.length - 1; y > x; y--) {
                if (nums[y] > nums[y-1]) {
                    int temp = nums[y];
                    nums[y] = nums[y-1];
                    nums[y-1] = temp;
                }
            }
        }

        return nums;
    }

    private int[] unreserve(int[] nums) {
        for(int x = nums.length - 1; x > 0; x--) {
            for(int y = 0; y < x; y++) {
                if(nums[y] > nums[y+1]) {
                    int temp = nums[y];
                    nums[y] = nums[y+1];
                    nums[y+1] =temp;
                }
            }
        }

        return nums;
    }

    public void printMapPao(int[] nums) {
        for(int num: nums) {
            System.out.print(num + "\t");
        }
    }

}
